﻿<MTreeview
    @bind-Open="@initiallyOpen"
    Items="items"
    Activatable
    ItemKey="u => u.Name"
    ItemChildren="u => u.Children"
    ItemText="u => u.Name"
    OpenOnClick>
    <PrependContent>
        @if (context.Item.File == null)
        {
            <MIcon>
                @(context.Open ? "mdi-folder-open" : "mdi-folder")
            </MIcon>
        }
        else
        {
            <MIcon>
                @files[context.Item.File]
            </MIcon>
        }
    </PrependContent>
</MTreeview>

@code {

    static Dictionary<string, string> files = new()
    {
        {"html", "mdi-language-html5"},
        {"js", "mdi-nodejs"},
        {"json", "mdi-code-json"},
        {"md", "mdi-language-markdown"},
        {"pdf", "mdi-file-pdf"},
        {"png", "mdi-file-image"},
        {"txt", "mdi-file-document-outline"},
        {"xls", "mdi-file-excel"}
    };

    static List<Project> items = new()
    {
        new Project(".git"),
        new Project("node_modules"),
        new Project("public", new List<Project>()
        {
            new Project("static", new List<Project>()
            {
                new Project("log.png", "png")
            }),
            new Project("favicon.ico", "png"),
            new Project("index.html", "html")
        }),
        new Project(".gitignore", "txt"),
        new Project("babel.config.js", "js"),
        new Project("package.json", "json"),
        new Project("README.md", "md"),
        new Project("vue.config.js", "js"),
        new Project("yarn.lock", "txt")
    };

    List<string> initiallyOpen = new() {"public"};

    public class Project
    {
        public string File { get; set; }

        public string Name { get; set; }

        public List<Project> Children { get; set; }

        public Project(string name)
        {
            Name = name;
        }

        public Project(string name, string file)
        {
            Name = name;
            File = file;
        }

        public Project(string name, List<Project> children)
        {
            Name = name;
            Children = children;
        }
    }

}